package com.training.commons;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.training.action.liuyong.LoginCodeAction;
import com.training.dao.impl.liuyong.AjaxDaoImpl;
import com.training.pojo.chengshu.UUser;

public class SessionIntercetor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {

		Object user = ActionContext.getContext().getSession().get("loginUser");
		Object action = invocation.getAction();

		System.out.println("loginUser = " + user);
		System.out.println("Action = " + action);

		if (action.getClass() == AjaxDaoImpl.class || action.getClass() == LoginCodeAction.class) {
			System.out.println("loginCheck..........................");
			return invocation.invoke();
		} else if (user != null && user instanceof UUser) {
			System.out.println("User check.........................."+((UUser)user).getUname());
			return invocation.invoke();
		} else {
			System.out.println("No user ............................");
			return "input";
		}
	}
}
